<?php

namespace addons\paotui\service;

class Config
{

    public $model;
    public static $_config;

    public static function init()
    {
        $configModel = new \app\admin\model\paotui\Config();
        $configList  = $configModel->select();
        $config      = [];
        foreach ($configList as $k => $v) {
            $config[$v['name']] = $v['value'];
        }

        self::$_config = $config;
    }

    /**
     * 获取配置值
     * @param $name
     * @return mixed
     */
    public static function get($name)
    {
        self::init();
        return self::$_config[$name];
    }

    /**
     * 设置配置值
     * @param $name
     * @param $value
     */
    public static function set($name, $value)
    {
        $configModel = new \app\admin\model\paotui\Config();
        $configModel->where(['name' => $name])->update(['value' => $value]);
    }

}